/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package renders;

import java.awt.Color;
import java.awt.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author root
 */
public class FechaRender extends DefaultListCellRenderer implements TableCellRenderer {
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        if (value instanceof Date){
            //Cambio el nombre de la columna en tiempo de ejecución
            table.getTableHeader().getColumnModel().getColumn(column).setHeaderValue("Fecha (Hora)");
            table.getTableHeader().repaint();
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy (hh:mm:ss)");
            setText(sdf.format((Date)value));
        }
        
        if ((row % 2) == 0) {
            this.setBackground(Color.white);
        } else {
            this.setBackground(new Color(242, 242, 242));
        }
        if (isSelected) {
            this.setForeground(Color.WHITE);
            this.setBackground(new Color(57, 105, 138));
        } else {
            this.setForeground(Color.BLACK);
        }
        
        return this;
    }
}
